;;; provide common base functionality for a pop up window that the
;;; user must interact with before returning to the regular diagram.
(defpackage :popup-mixin
  (:use :cl)
  (:export :popup-mixin
           :enabled-p
           :open-popup
           :close-popup))

(in-package :popup-mixin)

(defclass popup-mixin ()
  ((enabled-p :initform nil :reader enabled-p)))

(defgeneric enabled-p (obj))
(defgeneric open-popup (obj))
(defgeneric close-popup (obj))

(defmethod open-popup :after ((obj popup-mixin))
  (assert (not (enabled-p obj)))
  (setf (slot-value obj 'enabled-p) t))

(defmethod close-popup :after ((obj popup-mixin))
  (assert (enabled-p obj))
  (setf (slot-value obj 'enabled-p) nil))

(defmethod p:navigate-clean-up progn ((state popup-mixin) how)
  (when (enabled-p state)
    (close-popup state)))

(defmethod p:finish-input-arguments-collapse progn ((state popup-mixin))
  (when (enabled-p state) (close-popup state)))

(defmethod p:finish-fill-mode progn ((state popup-mixin))
  (when (enabled-p state) (close-popup state)))

(defmethod as:finish-collapsed-argument progn ((state popup-mixin) node)
  (when (enabled-p state) (close-popup state)))

(defmethod bt:before-undo-hook progn ((state popup-mixin))
  (when (enabled-p state)
    (close-popup state)))

(defclass diagram-popup-mixin (popup-mixin)
  ())
